package com.main;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class NPC_Steve extends NPC{
	public int xpos;
	public int ypos;
	public int interactNr;
	public Sprite activeSprite;
	int answer;
	int possibleAnswers;
	boolean[] questsGiven;
	boolean[] questsCompleted;
	boolean temp;
	public NPC_Steve(int x, int y){
		questsGiven = new boolean[2];
		questsCompleted = new boolean[2];	
		xpos = x;
		ypos = y;
		activeSprite = StaticTextures.lumberman2axe;
		interactNr = 0;
	}
	public void setActiveSprite(Sprite xs){		
		activeSprite = xs;
	}
	public void render(SpriteBatch sb){	
		activeSprite.setPosition(xpos*Game.tileWidth,ypos*Game.tileHeight);
		activeSprite.draw(sb);
	}
	public void interact(Game game) {
		if (questsGiven[0] == false) {
			if (interactNr == 0) {
				String[] strings = new String[2];
				strings[0] = "Adventurer: Hello there! Who are you if I may ask?";
				strings[1] = "Woodman: Greetings adventurer! I am Steve the ranger.\n" +
				"I could teach you how to chop wood if you're interested,\n" +
				"you'll surely need it if you're going to stay in the wilds.";
				game.convFrame.setStrings(strings);
				game.convFrame.show();
			} else if (interactNr == 1) {
				String[] strings = new String[3];
				strings[0] = "Say: Sure, that's awfully thoughtful of you old man!";
				strings[1] = "Say: Interesting, but I'm guessing you want something in return\n" +
				"right?";
				strings[2] = "Say: Sounds very troublesome, I think I'll be leaving.";
				possibleAnswers = 3;
				game.convFrame.setTalkOptions(strings);
				game.convFrame.show();
			} else if (interactNr == 2) {
				String[] strings = new String[1];
				if (answer == 1) {
					strings[0] = "Steve: That's me! I'm afraid I'll have to ask you to bring me\n" +
					"some flowers for my wife and some apples for my stomach to return\n" +
					"the favour. Bring me two red flowers, one blue flower and an apple\n" +
					"and I'll teach you anything you need to know!";
				} else if (answer == 2) {
					strings[0] = "Steve: You read me like a book son. I could really use some\n" +
					"flowers for my grumpy wife and a few apples for my rumbling stomach.\n" +
					"Bring me two red flowers, one blue flower and an apple and I'll teach\n" +
					"you anything you need to know!";
				} else if (answer == 3) {
					strings[0] = "Steve: Your loss lad, let me know if you change your mind.";
				}
				game.convFrame.setStrings(strings);
				game.convFrame.show();
			} else if (interactNr == 3) {
				if (answer == 1 || answer == 2) {
					questsGiven[0] = true;
				} else {
					questsGiven[0] = false;
				}
				interactNr = 0;
				game.interacting = false;
				game.convFrame.hide();
			}
		} else if (questsGiven[0] && !questsCompleted[0]){
			System.out.println("hasquest inr" + interactNr);
			if (interactNr == 0) {
				String[] strings = new String[3];
				strings[0] = "Say: Hey Steve! I've got the stuff you asked me to get for you!";
				strings[1] = "Say: Hey you, old man! I've got them vegetables you asked for.";
				strings[2] = "Say: What was it you wanted again?";
				possibleAnswers = 3;
				game.convFrame.setTalkOptions(strings);
				game.convFrame.show();
			} else if (interactNr == 1) {
				String[] strings = new String[1];
				if (answer == 1) {
					strings[0] = "Steve: That's great! Can I have them then?";
				} else if (answer == 2){
					strings[0] = "Steve: Give 'em to me then!";
				} else if (answer == 3) {
					strings[0] = "Steve: I wanted two red flowers, one blue flower and an apple!";
				}
				game.convFrame.setStrings(strings);
				game.convFrame.show();
			} else if (interactNr == 2) {
				String[] strings = new String[2];
				strings[0] = "*Give the man the stuff.";
				strings[1] = "*Keep the stuff.";
				game.convFrame.setTalkOptions(strings);
				game.convFrame.show();
			} else if (interactNr == 3) {
				String[] strings;
				if (answer == 1) {
					if (game.character.inventory.contains(StaticInventoryData.GameObject.Flower_Blue, 1) &&
							game.character.inventory.contains(StaticInventoryData.GameObject.Apple, 1) &&
							game.character.inventory.contains(StaticInventoryData.GameObject.Flower_Red, 2)) {
						game.character.inventory.removeObject(StaticInventoryData.GameObject.Apple, 1);
						game.character.inventory.removeObject(StaticInventoryData.GameObject.Flower_Blue, 1);
						game.character.inventory.removeObject(StaticInventoryData.GameObject.Flower_Red, 2);
						temp = true;
						strings = new String[4];
						strings[0] = "Steve: Wow, thank you!";
						strings[1] = "*Steve teaches you the art of the axe*";
						strings[2] = "Steve: Here, take my axe as a token of my gratitude!";
						strings[3] = "Steve: Me and my wife are actually looking for a new place\n" +
						"to live.. Maybe with your new found axe skills you could build me\n" +
						"a house and we could cooperate! I'd chop your wood and you could\n" +
						"supply us with food!";
						game.convFrame.setStrings(strings);
						game.convFrame.show();
						game.character.hotKeys.put(3, StaticInventoryData.GameObject.Axe);
					} else {
						strings = new String[1];
						strings[0] = "Steve: You don't have the required items. Come back later.";
						game.convFrame.setStrings(strings);
						game.convFrame.show();
					}
				} else if (answer == 2){
					strings = new String[2];
					strings[0] = "Steve: ...";
					strings[1] = "Steve: Cheap bastard...";
					game.convFrame.setStrings(strings);
					game.convFrame.show();
				}
			} else if (interactNr == 4) {
				System.out.println("STOPPED INTERACTING");
				if (temp) {
					questsGiven[1] = true;
					questsCompleted[0] = true;
				}
				interactNr = 0;
				game.interacting = false;
				game.convFrame.hide();
			}
		} else if (questsGiven[1]){
			if (interactNr == 0) {
				String[] strings;
				strings = new String[1];
				strings[0] = "Steve: Oh, it's you again! Did you build us a house yet?";
				game.convFrame.setStrings(strings);
				game.convFrame.show();
			} else if (interactNr == 1) {
				String[] strings;
				if (game.character.community.steves_house == null) {
					strings = new String[1];
					strings[0] = "Say: No. I did not build your house yet.";
					possibleAnswers = 1;
				} else {
					strings = new String[2];
					strings[0] = "Say: Yes. Your house is ready for you to move in!";
					strings[1] = "Say: Yes, but I'm not sure if I want you in my community..";
					possibleAnswers = 2;
				}
				game.convFrame.setTalkOptions(strings);
				game.convFrame.show();
			} else if (interactNr == 2) {
				String[] strings = new String[1];
				if (game.character.community.steves_house == null) {
					strings = new String[1];
					strings[0] = "Steve: Ok..";
				} else {

					if (answer == 1) {
						this.questsCompleted[1] = true;
						strings = new String[2];
						strings[0] = "Steve: Wow, really? That's great!";
						strings[1] = "Steve: Stefina, get out here! We're moving!";
					} else if (answer == 2){
						strings = new String[1];
						strings[0] = "Steve: Mean..";
					}
				}
				game.convFrame.setStrings(strings);
				game.convFrame.show();
			} else if (interactNr == 3) {
				interactNr = 0;
				game.interacting = false;
				game.convFrame.hide();
			}
		}
	}
	public void nextInteract(Game game) {
		interactNr++;
		interact(game);
	}
	public void say(int id, Game game) {
		if (id > 0 && id <= possibleAnswers) {
			System.out.println(id);
			answer = id;
			nextInteract(game);
		}
	}
}
